package demo.day12

import java.util.Arrays

//Kotlin 泛型扩展
fun main() {

}

// 所有类型都是泛型 对泛型类型扩展了函数 所有函数都可以使用
fun <T> T.showContent() = println("${if (this is String)"字符串长度为：${this.length}" else "输入的类型不是字符串"}")

fun <T> T.showTime() = println("你当前调用的时间是：${System.currentTimeMillis()}")

fun <T> T.showTypeAction(){
    when(this){
        is String -> "当前为String类型"
        is Int -> "当前为Int类型"
        is Char -> "当前为Char类型"
        is Float -> "当前为Float类型"
        is Double -> "当前为Double类型"
        is Arrays -> "当前为Arrays类型"
        is Boolean -> "当前为Boolean类型"
        is Unit -> "当前为Unit类型"
        else -> "当前类型未知"
    }
}